﻿//返回元素位置top,left,right,bottom
//传入元素object
//返回封装信息，如取top，则getPosition(o).top
function getPosition(o) {
    var temp = {};
    temp.left = temp.right = temp.top = temp.bottom = 0;
    var oWidth = o.offsetWith, oHeight = o.offsetheight;
    while (o != document.body) {
        temp.left += o.offsetLeft;
        temp.top += o.offsetTop;
        var border = parseInt(o.offsetParent.currentStyle.borderWidth);
        if (border) {
            temp.left += border;
            temp.top += border;
        }
        o = o.offsetParent;
    }
    temp.right = temp.left + oWidth;
    temp.bottom = temp.top + temp.oHeight;
    return temp;
}

//显示用户列表
var ShowBuyUser = function (e) {
    document.getElementById('movedivid').style.top = getPosition(e).top-305;
    document.getElementById('movedivid').style.left = getPosition(e).left-130;
    document.getElementById('movedivid').style.display = "block";
}

var CloseUserWin = function () {
    document.getElementById('movedivid').style.display = "none";
}
//验证发布及时商品
var CheckTimer = function () {
    if (document.getElementById("MainContent_TextBox1").value == "") {
        alert("请选择一个游戏物品发布");
        return false;
    }
    if (document.getElementById("MainContent_TextBox2").value == "") {
        alert("请选择一个买家");
        return false;
    }
    if (!CheckNum(document.getElementById("MainContent_price").value)) {
        alert("价格请输入数字");
        return false;
    }
    if (!CheckNum(document.getElementById("MainContent_goodcount").value)) {
        alert("数量请输入数字");
        return false;
    }
    return true;
}
//设置买家数据
var setUser = function (v, name) {
    document.getElementById("MainContent_TextBox2").value = v;
    document.getElementById("MainContent_person").value = name;
    document.getElementById('movedivid').style.display = "none";
}

//验证是否输入为数字
var CheckNum = function (v) {
    var re = /^[0-9]+.?[0-9]*$/;   //判断字符串是否为数字     //判断正整数 /^[1-9]+[0-9]*]*$/   
    if (!re.test(v)) {
        return false;
    }
    return true;
}

var CheckStoreInfo = function () {
    if (document.getElementById('MainContent_storename').value == "") {
        alert("请输入商店名称");
        return false;
    }
    return true;
}

//验证发布商店商品
var CheckStore = function () {
    if (document.getElementById("MainContent_TextBox1").value == "") {
        alert("请选择一个游戏物品发布");
        return false;
    }
    if (!CheckNum(document.getElementById("MainContent_price").value)) {
        alert("价格请输入数字");
        return false;
    }
    if (!CheckNum(document.getElementById("MainContent_num").value)) {
        alert("数量请输入数字");
        return false;
    }
    return true;
}

//打开付款窗口
var OpenPayWin = function (v,id,type) {
    if (v != null && v != "") {
        window.open('PayWin.aspx?p=' + v+'&id='+id+'&type='+type, 'newwindow', 'height=180, width=420, top=0, left=0, toolbar=no, menubar=no, scrollbars=no, resizable=no,location=n o, status=no');
    }
    else {
        alert("请选择一个物品进行付款");
    }
}

//打开确认交易窗口
var OpenEnterWin = function (v, id, type) {
    if (v != null && v != "") {
        window.open('EnterPay.aspx?p=' + v + '&id=' + id + '&type=' + type, 'newwindow', 'height=180, width=420, top=0, left=0, toolbar=no, menubar=no, scrollbars=no, resizable=no,location=n o, status=no');
    }
    else {
        alert("请选择一个物品进行确认交易");
    }
}
//验证服务
var CheckService = function () {
    if (document.getElementById("MainContent_title").value == "") {
        alert("请输入标题");
        return false;
    }
    return true;
}